<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>VUE监听属性</title>
        <script type="text/javascript" src="https://unpkg.com/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
            X坐标：<input v-model="x"/>，Y坐标<input v-model="y"/><br/>
            <p>{{formatPoint}}</p>
            <button @click="formatPoint = '100,200'">调用计算属性的set方法</button>
        </div>
    </body>
    <script type="text/javascript">
        var vueObj = new Vue({
            el: '#app',
            data: {
                x: '',
                y: ''
            },
            computed: {
                formatPoint: {
                    get: function() {
                        console.log("触发了计算属性");
                        if(this.x && this.y) {
                            return "(" + this.x + ", " + this.y + ")";
                        } else {
                            return null;
                        }
                    },
                    set: function(value) {
                        var arr = value.split(",");
                        console.log("准备修改X");
                        this.x = arr[0];
                        console.log("准备修改Y");
                        this.y = arr[1];
                    }
                }
            }
        });

        vueObj.$watch('x', function(newValue, oldValue) {
            console.log("X坐标值【旧：" + oldValue + ", 新：" + newValue + "】");
        });
    </script>
</html>